using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the Version class.
	/// </summary>
    [Serializable]
	public partial class VersionCollection : ActiveList<Version, VersionCollection>
	{	   
		public VersionCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>VersionCollection</returns>
		public VersionCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Version o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the VERSIONS table.
	/// </summary>
	[Serializable]
	public partial class Version : ActiveRecord<Version>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Version()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Version(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Version(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Version(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("VERSIONS", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int64;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarUserID = new TableSchema.TableColumn(schema);
				colvarUserID.ColumnName = "UserID";
				colvarUserID.DataType = DbType.Int32;
				colvarUserID.MaxLength = 0;
				colvarUserID.AutoIncrement = false;
				colvarUserID.IsNullable = false;
				colvarUserID.IsPrimaryKey = false;
				colvarUserID.IsForeignKey = false;
				colvarUserID.IsReadOnly = false;
				colvarUserID.DefaultSetting = @"";
				colvarUserID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserID);
				
				TableSchema.TableColumn colvarMediaType = new TableSchema.TableColumn(schema);
				colvarMediaType.ColumnName = "Media type";
				colvarMediaType.DataType = DbType.String;
				colvarMediaType.MaxLength = 50;
				colvarMediaType.AutoIncrement = false;
				colvarMediaType.IsNullable = true;
				colvarMediaType.IsPrimaryKey = false;
				colvarMediaType.IsForeignKey = false;
				colvarMediaType.IsReadOnly = false;
				colvarMediaType.DefaultSetting = @"";
				colvarMediaType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaType);
				
				TableSchema.TableColumn colvarBrand = new TableSchema.TableColumn(schema);
				colvarBrand.ColumnName = "Brand";
				colvarBrand.DataType = DbType.String;
				colvarBrand.MaxLength = 550;
				colvarBrand.AutoIncrement = false;
				colvarBrand.IsNullable = true;
				colvarBrand.IsPrimaryKey = false;
				colvarBrand.IsForeignKey = false;
				colvarBrand.IsReadOnly = false;
				colvarBrand.DefaultSetting = @"";
				colvarBrand.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBrand);
				
				TableSchema.TableColumn colvarVersionX = new TableSchema.TableColumn(schema);
				colvarVersionX.ColumnName = "Version";
				colvarVersionX.DataType = DbType.String;
				colvarVersionX.MaxLength = 550;
				colvarVersionX.AutoIncrement = false;
				colvarVersionX.IsNullable = true;
				colvarVersionX.IsPrimaryKey = false;
				colvarVersionX.IsForeignKey = false;
				colvarVersionX.IsReadOnly = false;
				colvarVersionX.DefaultSetting = @"";
				colvarVersionX.ForeignKeyTableName = "";
				schema.Columns.Add(colvarVersionX);
				
				TableSchema.TableColumn colvarDuration = new TableSchema.TableColumn(schema);
				colvarDuration.ColumnName = "Duration";
				colvarDuration.DataType = DbType.Int32;
				colvarDuration.MaxLength = 0;
				colvarDuration.AutoIncrement = false;
				colvarDuration.IsNullable = true;
				colvarDuration.IsPrimaryKey = false;
				colvarDuration.IsForeignKey = false;
				colvarDuration.IsReadOnly = false;
				colvarDuration.DefaultSetting = @"";
				colvarDuration.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDuration);
				
				TableSchema.TableColumn colvarAgency = new TableSchema.TableColumn(schema);
				colvarAgency.ColumnName = "Agency";
				colvarAgency.DataType = DbType.String;
				colvarAgency.MaxLength = 550;
				colvarAgency.AutoIncrement = false;
				colvarAgency.IsNullable = true;
				colvarAgency.IsPrimaryKey = false;
				colvarAgency.IsForeignKey = false;
				colvarAgency.IsReadOnly = false;
				colvarAgency.DefaultSetting = @"";
				colvarAgency.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAgency);
				
				TableSchema.TableColumn colvarAdvertiser = new TableSchema.TableColumn(schema);
				colvarAdvertiser.ColumnName = "Advertiser";
				colvarAdvertiser.DataType = DbType.String;
				colvarAdvertiser.MaxLength = 550;
				colvarAdvertiser.AutoIncrement = false;
				colvarAdvertiser.IsNullable = true;
				colvarAdvertiser.IsPrimaryKey = false;
				colvarAdvertiser.IsForeignKey = false;
				colvarAdvertiser.IsReadOnly = false;
				colvarAdvertiser.DefaultSetting = @"";
				colvarAdvertiser.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdvertiser);
				
				TableSchema.TableColumn colvarNoOfInsertions = new TableSchema.TableColumn(schema);
				colvarNoOfInsertions.ColumnName = "No_of_Insertions";
				colvarNoOfInsertions.DataType = DbType.Int64;
				colvarNoOfInsertions.MaxLength = 0;
				colvarNoOfInsertions.AutoIncrement = false;
				colvarNoOfInsertions.IsNullable = true;
				colvarNoOfInsertions.IsPrimaryKey = false;
				colvarNoOfInsertions.IsForeignKey = false;
				colvarNoOfInsertions.IsReadOnly = false;
				colvarNoOfInsertions.DefaultSetting = @"";
				colvarNoOfInsertions.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNoOfInsertions);
				
				TableSchema.TableColumn colvarInvestment = new TableSchema.TableColumn(schema);
				colvarInvestment.ColumnName = "Investment";
				colvarInvestment.DataType = DbType.Int64;
				colvarInvestment.MaxLength = 0;
				colvarInvestment.AutoIncrement = false;
				colvarInvestment.IsNullable = true;
				colvarInvestment.IsPrimaryKey = false;
				colvarInvestment.IsForeignKey = false;
				colvarInvestment.IsReadOnly = false;
				colvarInvestment.DefaultSetting = @"";
				colvarInvestment.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInvestment);
				
				TableSchema.TableColumn colvarClip = new TableSchema.TableColumn(schema);
				colvarClip.ColumnName = "Clip";
				colvarClip.DataType = DbType.String;
				colvarClip.MaxLength = 550;
				colvarClip.AutoIncrement = false;
				colvarClip.IsNullable = true;
				colvarClip.IsPrimaryKey = false;
				colvarClip.IsForeignKey = false;
				colvarClip.IsReadOnly = false;
				colvarClip.DefaultSetting = @"";
				colvarClip.ForeignKeyTableName = "";
				schema.Columns.Add(colvarClip);
				
				TableSchema.TableColumn colvarImage = new TableSchema.TableColumn(schema);
				colvarImage.ColumnName = "Image";
				colvarImage.DataType = DbType.String;
				colvarImage.MaxLength = 550;
				colvarImage.AutoIncrement = false;
				colvarImage.IsNullable = true;
				colvarImage.IsPrimaryKey = false;
				colvarImage.IsForeignKey = false;
				colvarImage.IsReadOnly = false;
				colvarImage.DefaultSetting = @"";
				colvarImage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarImage);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("VERSIONS",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public long Id 
		{
			get { return GetColumnValue<long>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("UserID")]
		[Bindable(true)]
		public int UserID 
		{
			get { return GetColumnValue<int>(Columns.UserID); }
			set { SetColumnValue(Columns.UserID, value); }
		}
		  
		[XmlAttribute("MediaType")]
		[Bindable(true)]
		public string MediaType 
		{
			get { return GetColumnValue<string>(Columns.MediaType); }
			set { SetColumnValue(Columns.MediaType, value); }
		}
		  
		[XmlAttribute("Brand")]
		[Bindable(true)]
		public string Brand 
		{
			get { return GetColumnValue<string>(Columns.Brand); }
			set { SetColumnValue(Columns.Brand, value); }
		}
		  
		[XmlAttribute("VersionX")]
		[Bindable(true)]
		public string VersionX 
		{
			get { return GetColumnValue<string>(Columns.VersionX); }
			set { SetColumnValue(Columns.VersionX, value); }
		}
		  
		[XmlAttribute("Duration")]
		[Bindable(true)]
		public int? Duration 
		{
			get { return GetColumnValue<int?>(Columns.Duration); }
			set { SetColumnValue(Columns.Duration, value); }
		}
		  
		[XmlAttribute("Agency")]
		[Bindable(true)]
		public string Agency 
		{
			get { return GetColumnValue<string>(Columns.Agency); }
			set { SetColumnValue(Columns.Agency, value); }
		}
		  
		[XmlAttribute("Advertiser")]
		[Bindable(true)]
		public string Advertiser 
		{
			get { return GetColumnValue<string>(Columns.Advertiser); }
			set { SetColumnValue(Columns.Advertiser, value); }
		}
		  
		[XmlAttribute("NoOfInsertions")]
		[Bindable(true)]
		public long? NoOfInsertions 
		{
			get { return GetColumnValue<long?>(Columns.NoOfInsertions); }
			set { SetColumnValue(Columns.NoOfInsertions, value); }
		}
		  
		[XmlAttribute("Investment")]
		[Bindable(true)]
		public long? Investment 
		{
			get { return GetColumnValue<long?>(Columns.Investment); }
			set { SetColumnValue(Columns.Investment, value); }
		}
		  
		[XmlAttribute("Clip")]
		[Bindable(true)]
		public string Clip 
		{
			get { return GetColumnValue<string>(Columns.Clip); }
			set { SetColumnValue(Columns.Clip, value); }
		}
		  
		[XmlAttribute("Image")]
		[Bindable(true)]
		public string Image 
		{
			get { return GetColumnValue<string>(Columns.Image); }
			set { SetColumnValue(Columns.Image, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varUserID,string varMediaType,string varBrand,string varVersionX,int? varDuration,string varAgency,string varAdvertiser,long? varNoOfInsertions,long? varInvestment,string varClip,string varImage)
		{
			Version item = new Version();
			
			item.UserID = varUserID;
			
			item.MediaType = varMediaType;
			
			item.Brand = varBrand;
			
			item.VersionX = varVersionX;
			
			item.Duration = varDuration;
			
			item.Agency = varAgency;
			
			item.Advertiser = varAdvertiser;
			
			item.NoOfInsertions = varNoOfInsertions;
			
			item.Investment = varInvestment;
			
			item.Clip = varClip;
			
			item.Image = varImage;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(long varId,int varUserID,string varMediaType,string varBrand,string varVersionX,int? varDuration,string varAgency,string varAdvertiser,long? varNoOfInsertions,long? varInvestment,string varClip,string varImage)
		{
			Version item = new Version();
			
				item.Id = varId;
			
				item.UserID = varUserID;
			
				item.MediaType = varMediaType;
			
				item.Brand = varBrand;
			
				item.VersionX = varVersionX;
			
				item.Duration = varDuration;
			
				item.Agency = varAgency;
			
				item.Advertiser = varAdvertiser;
			
				item.NoOfInsertions = varNoOfInsertions;
			
				item.Investment = varInvestment;
			
				item.Clip = varClip;
			
				item.Image = varImage;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn UserIDColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn MediaTypeColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn BrandColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn VersionXColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn DurationColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn AgencyColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn AdvertiserColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn NoOfInsertionsColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn InvestmentColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn ClipColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn ImageColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string UserID = @"UserID";
			 public static string MediaType = @"Media type";
			 public static string Brand = @"Brand";
			 public static string VersionX = @"Version";
			 public static string Duration = @"Duration";
			 public static string Agency = @"Agency";
			 public static string Advertiser = @"Advertiser";
			 public static string NoOfInsertions = @"No_of_Insertions";
			 public static string Investment = @"Investment";
			 public static string Clip = @"Clip";
			 public static string Image = @"Image";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
